/**
 * @param {number[]} postorder
 * @return {boolean}
 */

var verifyPostorder = function (postorder) {
    let len = postorder.length
    if (!len) {
        return true
    }
    const root = postorder[len - 1]
    for (var i = 0; i < len - 1; i++) {
        if (postorder[i] > root) {
            break
        }
    }
    for (let j = i; j < len - 1; j++) {
        if (postorder[j] < root) {
            return false
        }
    }
    let left = true
    if (i > 0) {
        left = verifyPostorder(postorder.slice(0, i))
    }
    let right = true
    if (i < len - 1) {
        right = verifyPostorder(postorder.slice(i, len - 1))
    }
    return left && right
};